import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ASUS
 * Date: 2024-12-09
 * Time: 15:19
 */
public class JDBCDemo4 {
    public static void main(String[] args) throws SQLException {
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource) dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/java_jdbc?characterEcoding=utf8&utfSSL=false");
        ((MysqlDataSource) dataSource).setUser("root");
        ((MysqlDataSource) dataSource).setPassword("123456");

        Connection connection = dataSource.getConnection();

        String sql = "insert into student values(2, 'lisi')";
        PreparedStatement statement = connection.prepareStatement(sql);

        int n = statement.executeUpdate();
        System.out.println("n = " + n);

        statement.close();
        connection.close();

    }
}
